import React, { Component } from 'react'
import "./less/Toggle.less"
import { ChangeSubApi } from '../request/api'
import { Link } from 'react-router-dom'

export default class toggle extends Component {
    state = {
        subArr:[]
    }
    render() {
        return (
            <div className="toggle_subject">
                <div className="top">
                    <section>
                        <span>首页显示学科-H5面试题</span>
                        <span>设置默认学科</span>
                    </section>
                    <h3>
                        <div>H5面试题</div>
                    </h3>
                </div>
                <div className="bottom">
                    <h3>专业科目</h3>
                    <ul>
                        {
                            this.state.subArr.map(item => (
                                <li key={item.id}>
                                    <Link to="/home">{item.title}</Link>
                                </li>
                            ))
                        }
                    </ul>
                </div>
            </div>
        )
    }
    componentDidMount() {
        // let token = localStorage.getItem("x-auth-token");
        console.log(this.props.match.params.actionCode);
        let actionCode = this.props.match.params.actionCode;
        ChangeSubApi({
            actionCode
        }).then(res => {
            if (res.errCode === 0) {
                console.log(res);
                let { data } = res;
                this.setState({
                    subArr:data
                })

                console.log(this.state.subArr);
            }
        })

        // if (!token) {
        //     // 显示loading
        //     this.props.openLoadingFn();
        //     // 过1.5秒关闭
        //     setTimeout(() => {
        //         this.props.closeLoadingFn();    // 关闭loading

        //         // 存储字体大小
        //         let fz = document.querySelector('html').style.fontSize;
        //         sessionStorage.setItem('fz', fz);

        //         // 没有token就跳到登录页
        //         this.props.history.push("/login");
        //     }, 1500)

        //     return;
        // }
    }
}
